use axum::{Json, response::IntoResponse};
use hyper::StatusCode;
use serde::{Deserialize, Serialize};


// basic handler that responds with a static string
pub async fn root() -> &'static str {
	"Hello, World!"
}

pub async fn create_user(
	// this argument tells axum to parse the request body
	// as JSON into a `CreateUser` type
	Json(payload): Json<CreateUser>,
) -> impl IntoResponse {
	// insert your application logic here
	let user = User {
			id: 1337,
			username: payload.username,
	};

	// this will be converted into a JSON response
	// with a status code of `201 Created`
	(StatusCode::CREATED, Json(user))
}

// the input to our `create_user` handler
#[derive(Deserialize)]
pub struct CreateUser {
	username: String,
}

// the output to our `create_user` handler
#[derive(Serialize)]
pub struct User {
	id: u64,
	username: String,
}